<template>
    <div class="switch">
      <div class="switch__1">
        <input id="switch-1" type="checkbox" :disabled="props.disabled" v-model="isChecked"/>
        <label for="switch-1"></label>
        test
      </div>
    </div>
</template>

<script lang="ts" setup>
import { ref,watch } from 'vue'


const emit =  defineEmits(['update:modelValue'])
const props = withDefaults(
  defineProps<{
    disabled?: boolean
  }>(),{
  }
)
const isChecked = ref(false)
watch(isChecked,(newVal)=>{
emit('update:modelValue', newVal)
})


</script>
<style lang="less" scoped>
/*  SWITCH  */
.switch {
  grid-column: 1/2;
  display: grid;
  grid-template-columns: repeat(2, -webkit-min-content);
  grid-template-columns: repeat(2, min-content);
  grid-gap: 3rem;
  justify-self: center;
}
.switch input {
  display: none;
}
.switch__1,
.switch__2 {
  width: 100px;
}
.switch__1 label,
.switch__2 label {
  display: flex;
  align-items: center;
  width: 100%;
  height: 45px;
  box-shadow: 0.3rem 0.3rem 0.6rem @greyLight-2, -0.2rem -0.2rem 0.5rem @white;
  background: rgba(255, 255, 255, 0);
  position: relative;
  cursor: pointer;
  border-radius: 1.6rem;
}
.switch__1 label::after,
.switch__2 label::after {
  content: "";
  position: absolute;
  left: 0.4rem;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 50%;
  background: @greyDark;
  transition: all 0.4s ease;
}
.switch__1 label::before,
.switch__2 label::before {
  content: "";
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(
    330deg,
    @primary-dark 0%,
    @primary 50%,
    @primary-light 100%
  );
  opacity: 0;
  transition: all 0.4s ease;
}
.switch input:checked ~ label::before {
  opacity: 1;
}
.switch input:checked ~ label::after {
  left: 57%;
  background: @greyLight-1;
}

.switch input:disabled ~ label {
  opacity: 0.4;
}

</style>
